﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;

namespace bowlingkata.tests
{
    [TestFixture]
    public class test_BowlingGame
    {
        [Test]
        [TestCase("00000000000000000000", 0)]
        [TestCase("44444444444444444444", 80)]
        [TestCase("AAAAAAAAAAAA", 300)]          // all strikes
        [TestCase("192837465555647382915", 154)] // all spares
        [TestCase("000000000000000000195", 15)]  // focus: just one more roll after spare in 10th frame
        [TestCase("000000000000000000a34", 17)]  // focus: two more rolls after strike in 10th frame
        [TestCase("3451a45267354aa375", 131)]    // acceptance test case from blog entry
        public void AcceptanceTest(string rolls, int expectedTotal)
        {
            var total = BowlingGame.CalculateTotal(String2Rolls(rolls));
            Assert.AreEqual(expectedTotal, total);
        }


        private static IEnumerable<int> String2Rolls(IEnumerable<char> rolls)
        {
            foreach (var r in rolls)
            {
                if (char.ToLower(r) == 'a')
                    yield return 10;
                else
                    yield return int.Parse(r.ToString());
            }
        }
    }
}
